using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using CasaBella.Entities;

namespace CasaBella.Repository.Mapping
{
    public class P_MUEBLESMap : EntityTypeConfiguration<P_MUEBLES>
    {
        public P_MUEBLESMap()
        {
            // Primary Key
            this.HasKey(t => t.PMueblesId);

            // Properties
            this.Property(t => t.PMueblesId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.Nombre)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("P_MUEBLES");
            this.Property(t => t.PMueblesId).HasColumnName("PMueblesId");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.IdMaterial).HasColumnName("IdMaterial");
            this.Property(t => t.IdMedida).HasColumnName("IdMedida");
            this.Property(t => t.IdModelo).HasColumnName("IdModelo");

            // Relationships
            this.HasOptional(t => t.MATERIAL)
                .WithMany(t => t.P_MUEBLES)
                .HasForeignKey(d => d.IdMaterial);
            this.HasOptional(t => t.MEDIDA_MUEBLE)
                .WithMany(t => t.P_MUEBLES)
                .HasForeignKey(d => d.IdMedida);
            this.HasOptional(t => t.MODELO_MUEBLE)
                .WithMany(t => t.P_MUEBLES)
                .HasForeignKey(d => d.IdModelo);
            this.HasRequired(t => t.PRODUCTO)
                .WithOptional(t => t.P_MUEBLES)
                .WillCascadeOnDelete(false);
        }
    }
}
